<%@page import="com.j3l11234.myy_sign.entity.UserEntity"%>
<%@ page contentType="text/html;charset=utf-8"  language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<jsp:include page="../header.jsp" />

<jsp:include page="../navbar.jsp" />
	
<div class="container-fluid container-margin-top">
	<div class="row">
		<div class="col-lg-2 col-sm-3">
			<jsp:include page="../admin/sidebar.jsp" />
		</div>

		<div class="col-lg-10 col-sm-9">
			<c:choose>
				<c:when test="${result == true}">
					<div class="dialog dialog-success"><strong><c:out value="${resultText}"/></strong></div>
				</c:when>
				<c:when test="${result == false}">
					<div class="dialog dialog-danger"><strong><c:out value="${resultText}"/></strong></div>
				</c:when>
			</c:choose>

			<div class="dialog dialog-info">
				<form class="form-horizontal" role="form" action="<c:url value="/user/edit.do"/>" method="post" style="text-align: initial;">
					<input type="hidden" id="input-privilege" value="${editUser.privilege}" name="privilege">
					<input type="hidden" value="${editUser.id}" name="user_id">
					<div class="form-group">
						<label for="inputUsername" class="col-sm-2 control-label">用户名</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="inputUsername" name="username" placeholder="用户名" value="${editUser.username}" required>
						</div>
					</div>
					<div class="form-group">
						<label for="inputPassword" class="col-sm-2 control-label">密码</label>
						<div class="col-sm-10">
							<input type="password" class="form-control" id="inputPassword" name="password" placeholder="留空则不修改">
						</div>
					</div>
					<div class="form-group">
						<label for="inputAlias" class="col-sm-2 control-label">昵称</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="inputAlias" placeholder="昵称" name="alias" value="${editUser.alias}" required>
						</div>
					</div>
					<div class="form-group">
						<div class="col-sm-offset-2 col-sm-10">
							<label class="checkbox" for="checkbox2">
								<input type="checkbox" id="input-checkbox-admin"> 管理员
							</label>
							<label class="checkbox" for="checkbox2">
								<input type="checkbox" id="input-checkbox-manager"> 经理
							</label>
							<label class="checkbox" for="checkbox2">
								<input type="checkbox" id="input-checkbox-worker"> 员工
							</label>
						</div>
					</div>
					<div class="form-group">
						<div class="col-sm-offset-2 col-sm-3">
							<button type="submit" class="btn btn-success">提交</button>
						</div>
						<div class="col-sm-offset-2 col-sm-3">
							<a href="<c:url value="/user/delete.do?user=${editUser.id}"/>" class="btn btn-danger" role="button">删除</a>
						</div>
					</div>
				</form>
			</div>       
		</div>
	</div>
</div>
<script>
	document.title = "修改用户信息";
	$(function(){
		var privilege = $("#input-privilege").val();
		if((privilege & 1) == 1){
			$("#input-checkbox-worker").prop('checked',true);
		}
		if((privilege & 2) == 2){
			$("#input-checkbox-manager").prop('checked',true);
		}
		if((privilege & 4) == 4){
			$("#input-checkbox-admin").prop('checked',true);
		}


		$("#input-checkbox-admin").click(function(){
			setPrivilege($("#input-checkbox-admin").prop('checked'),4);
		});
		$("#input-checkbox-manager").click(function(){
			setPrivilege($("#input-checkbox-manager").prop('checked'),2);
		});
		$("#input-checkbox-worker").click(function(){
			setPrivilege($("#input-checkbox-worker").prop('checked'),1);
		});

		function setPrivilege(checked,value){
			var $checkbox = $("#input-privilege");
			var privilege = $checkbox.val();
			if(checked){
				privilege |= value;
			}else{
				privilege &= (~value);
			}
			console.log(privilege);
			$checkbox.val(privilege);
		}
	});


</script>

<jsp:include page="../footer.jsp" />

